package server.business.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import server.business.pojo.BloodInBoundData;
import server.business.service.BloodInBoundService;
import server.business.service.BloodInformationService;
import server.business.vo.Result;
import server.business.vo.ResultExpand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Controller
@RequestMapping("/bloodInBound")
public class BloodInBoundController {
    
    @Autowired
    private BloodInBoundService bloodInBoundService;
    
//    @RequestMapping("/bloodInBound")
//    public String toBloodInBound(){
//        return "pages/bloodInBound";
//    }

    /**
     * 所有血液入库信息数据
     *
     * @return {@link List}<{@link BloodInBoundData}>
     */
    @RequestMapping("/normal/query")
    @ResponseBody
    public List<BloodInBoundData> queryData(){
        List<BloodInBoundData> list = bloodInBoundService.queryData();
        return list;
    }
    
    @RequestMapping("/normal/listByPage")
    @ResponseBody
    public ResultExpand getPage(HttpServletRequest request, HttpServletResponse response){
        Integer currentPage = Integer.parseInt(request.getParameter("currentPage"));
        Integer pageSize = Integer.parseInt(request.getParameter("pageSize"));
        IPage<BloodInBoundData> bloodInBoundDataIPage = bloodInBoundService.selectByPage(currentPage, pageSize);
        ResultExpand resultExpand = new ResultExpand("200", "成功", bloodInBoundDataIPage.getRecords(), currentPage, pageSize, bloodInBoundDataIPage.getTotal(), bloodInBoundDataIPage.getPages());
        return resultExpand;
    }

    /**
     * 搜索血液入库信息
     *
     * @param request  请求
     * @param response 响应
     * @return {@link ResultExpand}
     */
    @RequestMapping("/normal/searchBloodInBound")
    @ResponseBody
    public ResultExpand searchBloodInBound(HttpServletRequest request, HttpServletResponse response){
        ResultExpand resultExpand = new ResultExpand();
        resultExpand =  bloodInBoundService.searchBloodInBound(request, response);
        return resultExpand;
    }

    /**
     * 新增血液入库信息
     *
     * @param 
     * @return {@link Result}
     */
    @RequestMapping("/normal/addBloodInBound")
    @ResponseBody
    public Result addBloodInBound(@RequestBody String json) {
        Result result = bloodInBoundService.addBloodInBound(json);
        return result;
    }
    
    @RequestMapping("/review/reviewBloodInBound")
    @ResponseBody
    public Result reviewBloodInBound(HttpServletRequest request, HttpServletResponse response) {
        Result result = new Result();
        result = bloodInBoundService.reviewBloodInBound(request, response);
        return result;
    }
    
    @RequestMapping("/review/cancelBloodInBound")
    @ResponseBody
    public Result cancelBloodInBound(HttpServletRequest request, HttpServletResponse response) {
        Result result = new Result();
        result = bloodInBoundService.cancelBloodInBound(request, response);
        return result;
    }
    
    @RequestMapping("/normal/getBloodInformation")
    @ResponseBody
    public Result getBloodInformation(HttpServletRequest request, HttpServletResponse response) {
        Result result = new Result();
        result = bloodInBoundService.getBloodInformation(request, response);
//        System.out.println(result.getData());
        return result;
    }

    @RequestMapping("/normal/downloadExcel")
    public void downloadExcel(HttpServletRequest request, HttpServletResponse response){
        bloodInBoundService.downloadExcel(request, response);
    }
}
